import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { service } from '@ember/service';

export default class TInputComponent extends Component {
  @service call;

  @tracked items = [];

  constructor() {
    super(...arguments);
    // 监听自定义事件
    document.body.addEventListener('showMessage', (event) => {
        event.detail.messageId = this.call.generateUUID();
        // 显示消息
        this.items = [...this.items, event.detail];
        // 定时关闭
        setTimeout(() => {this.closeMessageById(event.detail.messageId);}, 3600);
    });
  }

  @action
  closeMessage($event) {
    this.closeMessageById($event.target.id);
  }

  closeMessageById(messageId) {
    this.items = this.items.filter(item => item.messageId != messageId);
  }
  
}